<template>
      <input-select ref="glfselects" :id="id" :postUrl="postUrl" :dataField="dataField" :extype="extype" @selectdata="selectdata" :options="options" :index="index"   :data="data"  @input="changeData" :isreadonly="isreadonly"  :valsql="valsql" :valsql2="valsql2" :sign="sign" :time="time"  :sign2="sign2" :time2="time2"  :appid="appid" :exkey="exkey"></input-select>
                        
</template>
<script>
import InputSelect  from '../input/input-select'
export default {
    name:"glfSelect",
    props:['id','options','styles','value','data','index','isreadonly','isBorder','extype','valsql','appid','dataField','isSearch','isChange','exkey','sign','time','postUrl','isEdit','valsql2','sign2','time2'],
    components:{
        InputSelect
    },
    data(){
       return{
           a_ex11:"",
           options:[],
           gm_id:""
       }
    },
    created(){
        try{
            this.gm_id=this.data["gmInfo"].gm_id;
        }catch(e){}
    },
    methods:{
        changeData(data){
            this.$emit("input",data);
        },
        selectdata(data){
            this.options=JSON.parse(data);
        },
        getNowFormatDate() {
            var date = new Date();
            var seperator1 = "-";
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentdate = year + seperator1 + month + seperator1 + strDate;
            return currentdate;
        }

    },
    watch:{
         data:{
            handler: function (newVal) {
                console.log("watch=================================")
                let a_ex11=this.data["after"].a_ex11;
              
                if(this.a_ex11!=a_ex11){
                    this.a_ex11=a_ex11;
                    let gcb_dat4="";
                    let gcb_dat5="";
                    for(let i=0;i<this.options.length;i++){
                        let gcb_id=this.options[i].gcb_id;
                        if(gcb_id==a_ex11){
                            gcb_dat4=this.options[i].gcb_dat4;
                            gcb_dat5=this.options[i].gcb_dat5;
                        }
                    }
                    if(gcb_dat4=='1900-01-01'||gcb_dat4==''){
                        gcb_dat4=this.getNowFormatDate();
                    }
                    if(gcb_dat5=='1900-01-01'||gcb_dat5==''){
                        gcb_dat5=this.getNowFormatDate();
                    }else{
                        let date_=new Date(gcb_dat5);
                        date_=date_.setDate(date_.getDate()+1);
                        date_=new Date(date_);
                        var year_ = date_.getFullYear();//当前时间的年份减去一年
                        var month_ =date_.getMonth()+1;//时间的月份获取
                        var day_ = date_.getDate();//时间的日，获取


                    
                        if(month_<10){
                            month_="0"+month_;
                        }
                        if(day_<10){
                            day_="0"+day_;
                        }
                        gcb_dat5 = year_+'-'+month_+'-'+day_;//时间进行拼接
                    }
                    

                    this.$set(this.data["after"],"a_dat1",gcb_dat5);
                    let date=new Date(gcb_dat5);
                    date.setFullYear(date.getFullYear()+Number(this.data["after"].a_ex5)); 
                    if(Number(this.data["after"].a_ex5)!=0){
                        date=date.setDate(date.getDate()-1);
                        date=new Date(date);
                    }
                    
                    var year = date.getFullYear();//当前时间的年份减去一年
                    var month = date.getMonth()+1;//时间的月份获取
                    var day = date.getDate();//时间的日，获取
                  
                    if(month<10){
                        month="0"+month;
                    }
                    if(day<10){
                        day="0"+day;
                    }
                    var time = year+'-'+month+'-'+day;//时间进行拼接
                    this.$set(this.data["after"],"a_dat2",time);
                }
                
                if(this.gm_id!=this.data["gmInfo"].gm_id){
                   
                    this.gm_id=this.data["gmInfo"].gm_id;
                    this.$refs.glfselects.getSelect2(this.gm_id);
                }
            },      
            deep: true    //深度监听
         }
    }
}
</script>